﻿using ASP;
using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using System;
using System.Collections;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;

public partial class Admin_Admin_ShopBankrollItemView : Admin, IRequiresSessionState
{
    private Pagination _pagehander;
    private string wherestr = "";
    private string orderbystr = "";
    private string linkhead = "";
    private bool tag = true;
    private IDbDataParameter[] param = null;
    private ArrayList al = new ArrayList();
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected Pagination m_pagehander
    {
        get
        {
            Pagination pagehander;
            if (this._pagehander == null)
            {
                this._pagehander = new Pagination();
                this._pagehander.SQL_LeftJoinTable = "HL_User";
                this._pagehander.SQL_LeftJoinField = "UserName";
                this._pagehander.SQL_JoinField2 = "UserID";
                this._pagehander.SQL_JoinField = "UserID";
                this._pagehander.P_Object = "记录";
                pagehander = this._pagehander;
            }
            else
            {
                pagehander = this._pagehander;
            }
            return pagehander;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(22))
        {
            base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "ShopBank");
            base.WriteRightErrMsg();
        }
        if (!base.IsPostBack)
        {
            this.BindList();
        }
        this.TxtBeginDate.Attributes.Add("onClick", string.Concat(new string[]
		{
			"show_cele_date(",
			this.TxtBeginDate.UniqueID,
			",'','',",
			this.TxtBeginDate.UniqueID,
			");"
		}));
        this.TxtEndDate.Attributes.Add("onClick", string.Concat(new string[]
		{
			"show_cele_date(",
			this.TxtEndDate.UniqueID,
			",'','',",
			this.TxtEndDate.UniqueID,
			");"
		}));
    }
    protected void BindList()
    {
        this.QueryString();
        int num = Fetch.GetID("page");
        if (num == 0)
        {
            num = 1;
        }
        int pageSize = this.GridView1.PageSize;
        if (this.al.Count > 0)
        {
            this.param = new IDbDataParameter[this.al.Count];
            this.al.CopyTo(this.param, 0);
        }
        if (this.param != null)
        {
            this.GridView1.DataSource = this.m_pagehander.GetDataTable("HL_AccountDetails", num, pageSize, "ID", this.wherestr, this.orderbystr, this.conn, this.param);
        }
        else
        {
            this.GridView1.DataSource = this.m_pagehander.GetDataTable("HL_AccountDetails", num, pageSize, "ID", this.wherestr, this.orderbystr, this.conn, null);
        }
        this.GridView1.DataBind();
        this.m_pagehander.P_LinkHead = this.linkhead;
        this.PagePanel.Text = this.m_pagehander.ShowPagePanel();
    }
    protected void QueryString()
    {
        string text = Fetch.Get("un");
        if (text != string.Empty && this.tag)
        {
            this.TxtUserName.Text = text;
        }
        else
        {
            text = this.TxtUserName.Text;
        }
        if (text != string.Empty)
        {
            this.wherestr += "and HL_AccountDetails.UserID in (Select UserID From [HL_User] Where UserName like '%'+ @UserName +'%') ";
            this.al.Add(this.conn.CreateParameter("@UserName", DbType.String, text));
            this.linkhead = this.linkhead + "&un=" + base.Server.UrlEncode(text);
        }
        string text2 = Fetch.Get("type");
        if (text2 != string.Empty && this.tag)
        {
            this.Dropincome_output.Text = text2;
        }
        else
        {
            text2 = this.Dropincome_output.SelectedValue;
        }
        if (text2 != string.Empty)
        {
            this.wherestr = this.wherestr + "and HL_AccountDetails.cType=" + text2 + " ";
            this.linkhead = this.linkhead + "&type=" + text2;
        }
        string text3 = Fetch.Get("bt");
        string text4 = Fetch.Get("et");
        if (text3 != string.Empty && this.tag)
        {
            this.TxtBeginDate.Text = text3;
        }
        else
        {
            text3 = this.TxtBeginDate.Text;
        }
        if (text4 != string.Empty && this.tag)
        {
            this.TxtEndDate.Text = text4;
        }
        else
        {
            text4 = this.TxtEndDate.Text;
        }
        if (text3 != string.Empty)
        {
            if (text4 != string.Empty)
            {
                if (Convert.ToDateTime(text4) < Convert.ToDateTime(text3))
                {
                    this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
                }
            }
            this.wherestr += "and DateDiff(d, CreateTime, @BeginDate)<=0 ";
            this.al.Add(this.conn.CreateParameter("@BeginDate", DbType.DateTime, text3));
            this.linkhead = this.linkhead + "&bt=" + text3;
        }
        if (text4 != string.Empty)
        {
            this.wherestr += "and DateDiff(d, CreateTime, @EndDate)>=0 ";
            this.al.Add(this.conn.CreateParameter("@EndDate", DbType.DateTime, text4));
            this.linkhead = this.linkhead + "&et=" + text4;
        }
        if (this.wherestr != "")
        {
            this.wherestr = "and" + this.wherestr;
            this.wherestr = this.wherestr.Replace("andand", "where");
        }
    }
    protected void OnSearch(object sender, EventArgs e)
    {
        this.tag = false;
        this.BindList();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string value = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
        this.conn.Execute("delete HL_AccountDetails where [ID]=@Id", new IDbDataParameter[]
		{
			this.conn.CreateParameter("@Id", DbType.String, value)
		});
        base.Response.Redirect(base.Request.RawUrl);
    }
}
